﻿// JScript 文件

// 说明：用 Javascript 操作 Cookie 
  
//function getCookie( name ) 
//{
//    var start = document.cookie.indexOf( name + "=" );
//    var len = start + name.length + 1;     
//    if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) 
//    {         
//        return null;     
//    }     
//    if ( start == -1 ) 
//    {
//        return null;
//    }
//    var end = document.cookie.indexOf( ';', len );     
//    if ( end == -1 ) 
//    {
//        end = document.cookie.length;
//    }
//    return unescape( document.cookie.substring( len, end ) ); 
//}  
//function setCookie( name, value) 
//{     
//    var Days = 1; 
//    var exp  = new Date();
//    exp.setTime(exp.getTime() + Days*5*60*1000);
//    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
//}  
//function deleteCookie(name) 
//{        
//    var exp = new Date();
//    exp.setTime(exp.getTime() - 1);
//    var cval=getCookie(name);
//    if(cval!=null) 
//    {
//        document.cookie= name + "="+cval+";expires="+exp.toGMTString();
//    }
//} 

// Create a cookie with the specified name and value.
// The cookie expires at the end of the 20th century.
function SetCookie(sName, sValue)
{
    date = new Date();
    document.cookie = sName + "=" + escape(sValue) + "; expires=" + date.toGMTString();
}

// Retrieve the value of the cookie with the specified name.
function GetCookie(sName)
{
    // cookies are separated by semicolons
    var aCookie = document.cookie.split("; ");
    for (var i=0; i < aCookie.length; i++)
    {
        // a name/value pair (a crumb) is separated by an equal sign
        var aCrumb = aCookie[i].split("=");
        if (sName == aCrumb[0])
        return decodeURI(aCrumb[1]);
    }
    // a cookie with the requested name does not exist
    return null;
}

// Delete the cookie with the specified name.
function DelCookie(sName)
{
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    document.cookie = sName + "=" + escape(sValue) + "; expires="+exp.toGMTString();
}
